/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Models;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author phuong
 */
@ManagedBean
@RequestScoped
public class Enquiry {

    int id, companyID, driverID;
    String name, phone, email, description;
    Date expectedDate;

    public Enquiry(int id, int companyID, int driverID, String name, String phone, String email, String description, Date expectedDate) {
        this.id = id;
        this.companyID = companyID;
        this.driverID = driverID;
        this.name = name;
        this.phone = phone;
        this.email = email;
        this.description = description;
        this.expectedDate = expectedDate;
    }

    public int getCompanyID() {
        return companyID;
    }

    public void setCompanyID(int companyID) {
        this.companyID = companyID;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getDriverID() {
        return driverID;
    }

    public void setDriverID(int driverID) {
        this.driverID = driverID;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getExpectedDate() {
        return expectedDate;
    }

    public void setExpectedDate(Date expectedDate) {
        this.expectedDate = expectedDate;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
    UIInput dateInput;

    public UIInput getDateInput() {
        return dateInput;
    }

    public void setDateInput(UIInput dateInput) {
        this.dateInput = dateInput;
    }
    
     public void validateDate(FacesContext context, UIComponent component, Object value)throws ValidatorException{            
       DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
       Date date = new Date();                        
       Date now = new Date(dateFormat.format(date));
                     
       Date d = (Date)value;
            
       if(!isValid(d, now))
       {
           throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error: ","Date entered must be greater than current date"));                
       }
    }
        
     
    private static boolean isValid(Date inputDate,Date compareDate){
        if(inputDate.getTime()< compareDate.getTime())
        return false;
        else
        return true;
    }
    /** Creates a new instance of Enquiry */
    public Enquiry() {
    }
}
